﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// ManageExamineePage.xaml 的交互逻辑
        /// </summary>
        public partial class ManageBooksPage : Page
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public ManageBooksPage()
                {
                        InitializeComponent();
                }

                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        if (_gm.LoginEmployee == null)
                        {
                                MessageBox.Show("请先登录系统");
                                NavigationService.Navigate(new Uri("StartPage.xaml", UriKind.Relative));
                        }
                        LayoutRoot.DataContext = _gm;
                }

                private void CreateBookButton_Click(object sender, RoutedEventArgs e)
                {
                        NavigationService.Navigate(new Uri("CreateBookPage.xaml", UriKind.Relative));
                }

                private void DeleteBookButton_Click(object sender, RoutedEventArgs e)
                {
                        // 在此处新建事件处理程序实现。
                        if (_gm.Book == null)
                        {
                                MessageBox.Show("请选择要删除的学校");
                                return;
                        }

                        if (
                                MessageBox.Show("确定要删除" + _gm.Book.Name + "及其所属校区吗？",
                                                "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                                _gm.Book.Delete();
                                _gm.Book = null;

                                NavigationService.Navigate(new Uri("ManageBooksPage.xaml", UriKind.Relative));
                        }
                }

                private void BooksListBox_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
                {
                        if (_gm.Book == null)
                        {
                                MessageBox.Show("请选择要查看校区的学校");
                                return;
                        }

                        NavigationService.Navigate(new Uri("ManageBookBranchsPage.xaml", UriKind.Relative));
                }

                
                
        }
}